﻿@using EmployeeLeaveSystem.Shared;
@using EmployeeLeaveSystem.Shared.Models;
@inject IMessageService _MessageService;
@inject HttpClient _HttpClient;
@inject ModalService _modalService;

<h3>部门调动历史</h3>
<Table DataSource="listMoveDepartment" TItem="AddMoveDepartment">
    <PropertyColumn Property="c=>c.Id" />
    <PropertyColumn Property="c=>c.Created" />
    <PropertyColumn Property="c=>c.Reason" />
    <PropertyColumn Property="c=>c.ToDepartment">@context.ToDepartment.Name</PropertyColumn>
    <ActionColumn>
        <Button OnClick="async ()=>{await OpenModalMove(context.Id);}">查看</Button>
    </ActionColumn>
</Table>
<h3>退休申请历史</h3>
<Table DataSource="listRetireMove" TItem="AddRetireMove">
    <PropertyColumn Property="c=>c.Id" />
    <PropertyColumn Property="c=>c.Created" />
    <PropertyColumn Property="c=>c.Reason" />
    <ActionColumn>
        <Button OnClick="async ()=>{await OpenModalRetire(context.Id);}">查看</Button>
    </ActionColumn>
</Table>
@code {
    List<AddMoveDepartment> listMoveDepartment = new();
    List<AddRetireMove> listRetireMove = new();
    protected override async Task OnInitializedAsync() {
        listMoveDepartment = await _HttpClient.GetFromJsonAsync<List<AddMoveDepartment>>($"api/Move/GetMoveInfos?usrId={GobalManager.myInfo?.Id}");
        InvokeAsync(StateHasChanged);
        listRetireMove = await _HttpClient.GetFromJsonAsync<List<AddRetireMove>>($"api/Move/GetRetireInfos?usrId={GobalManager.myInfo?.Id}");

        InvokeAsync(StateHasChanged);
        _MessageService.Success("获取历史记录成功");
    }

    // 模态对话框 部门调动详情
    bool _showModalMove = false;
    int MoveId = 1;
    private async Task OpenModalMove(int Id) {
        var modalConfig = new ModalOptions {
                    Title = "详情",
                    Draggable = true,
                    Footer = null,
                    Maximizable = true,
                    Width = "80vw",
                    Content = @<ViewPeopleMove Id="Id" />
            };

        await _modalService.CreateModalAsync(modalConfig);
    }


    // 模态对话框 部门调动详情
    bool _showModalRetire = false;
    int RetireId = 1;
    private async Task OpenModalRetire(int Id) {
        var modalConfig = new ModalOptions {
                    Title = "详情",
                    Draggable = true,
                    Footer = null,
                    Maximizable = true,
                    Width = "80vw",
                    Content = @<ViewRetireMove Id="Id" />
        };

        await _modalService.CreateModalAsync(modalConfig);
    }
}
